package com.caregiver.watch.business.user.model.vo;

import com.caregiver.watch.business.user.model.po.User;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.time.LocalDateTime;

/**
 * @Description: 用户信息
 * @Author 疆戟
 * @Date 2025/8/22 21:05
 * @Version 1.0
 */
@Data
@Schema(title = "用户信息")
public class UserInfoVo {

    /**
     * 用户ID
     */
    @Schema(description= "用户ID")
    private Long userId;

    /**
     * 用户账号
     */
    @Schema(description= "用户账号")
    private String username;

    /**
     * 用户昵称
     */
    @Schema(description= "用户昵称")
    private String nickName;

    /**
     * 用户邮箱
     */
    @Schema(description= "用户邮箱")
    private String email;

    /**
     * 手机号码
     */
    @Schema(description= "手机号码")
    private String phoneNumber;

    /**
     * 邀请码
     */
    @Schema(description= "邀请码")
    private String inviteCode;

    /**
     * 头像地址
     */
    @Schema(description= "头像地址")
    private String avatar;


    @Schema(description= "是否实名认证")
    private Boolean isRealName;

    @Schema(description= "是否开通健康预警")
    private Boolean isOpenHealthWarning;

    @Schema(description= "健康预警到期时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime healthWarningExpireTime;

    public static UserInfoVo build(User user) {
        UserInfoVo userInfoVo = new UserInfoVo();
        userInfoVo.setUserId(user.getUserId());
        userInfoVo.setUsername(user.getUsername());
        userInfoVo.setNickName(user.getNickName());
        userInfoVo.setEmail(user.getEmail());
        userInfoVo.setPhoneNumber(user.getPhoneNumber());
        userInfoVo.setInviteCode(user.getInviteCode());
        userInfoVo.setAvatar(user.getAvatar());
        userInfoVo.setIsRealName(StringUtils.isNoneBlank(user.getRealName(), user.getIdCard()));
        return userInfoVo;
    }
}
